<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla view library
jimport('joomla.application.component.view');

/**
 * HTML View class for the Product Component
 */
class ProductViewCategory extends JView
{
	// Overwriting JView display method
	function display($tpl = null) {
		// Assign data to the view
		$this->category = $this->get('Category');
		$this->items = $this->get('Items');
		$this->pagination = $this->get('Pagination');

		// Prepare data
		foreach ($this->items as $item) {
			$item->thumbnail = JURI::root() . 'images/products/' . $item->code . '/thumbnail.jpg';
			$item->link = JRoute::_('index.php?option=com_product&view=product&id=' . $item->id);
			$item->cartLink = JRoute::_('index.php?option=com_product&task=cart.add&id=' . $item->id);
		}
		
		//var_dump($this->items);
		//exit();
		
		// Check for errors.
		if (count($errors = $this->get('Errors'))) {
			JLog::add(implode('<br />', $errors), JLog::WARNING, 'jerror');
			return false;
		}
		
		// Display the view
		parent::display($tpl);
	}
}